#  Copyright (c) 2020 - ~, WANGXI
#  
#  GRAMMA UNINTEST TCL FILE
#  Used in NS-2 simulator
#  Clone from https://gitee.com/WangXi_Chn/ns2_modulelib
#  Note in https://www.yuque.com/wangxi_chn/kozrfl
#  
#  Change Logs:
#  Date           Author       Notes			Mail
#  2020-11-24     WangXi   	   first version	WangXi_Chn@foxmail.com

# There are four nodes
# node_0 - node_2
# node_1 - node_2
# node_2 - node_3
# FTP service run on trace node_0 to node_3
# CBR service run on trace node_1 to node_3

set ns [new Simulator]

$ns color 1 Blue
$ns color 2 Red

set nf [open out.nam w]
$ns namtrace-all $nf

set nd [open out.tr w]
$ns trace-all $nd

proc finish {} {
    global ns nf nd
    $ns flush-trace
    close $nf
    close $nd 
    exec nam out.nam &
    exit 0
}

set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]

$ns duplex-link $n0 $n2 2Mb 10ms DropTail
$ns duplex-link $n1 $n2 2Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail

$ns queue-limit $n2 $n3 10

$ns duplex-link-op $n0 $n2 orient right-down
$ns duplex-link-op $n1 $n2 orient right-up
$ns duplex-link-op $n2 $n3 orient right

set tcp [new Agent/TCP]
$tcp set class_ 2
$ns attach-agent $n0 $tcp
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
$ns connect $tcp $sink
$tcp set fid_ 1

set ftp [new Application/FTP]
$ftp attach-agent $tcp
$ftp set type_ FTP

set udp [new Agent/UDP]
$ns attach-agent $n1 $udp
set null [new Agent/Null]
$ns attach-agent $n3 $null

$ns connect $udp $null
$udp set fid_ 2

set cbr [new Application/Traffic/CBR]
$cbr attach-agent $udp
$cbr set type_ CBR
$cbr set packet_size_ 1000
$cbr set rate_ 1Mb
$cbr set random_ false

$ns at 0.1 "$cbr start"
$ns at 1.0 "$ftp start"
$ns at 4.0 "$ftp stop"
$ns at 4.5 "$cbr stop"

$ns at 5.0 "finish"

$ns run

#/************************ (C) COPYRIGHT 2020 WANGXI **************END OF FILE****/
